
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>图书交易平台</title>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<%--    <link href="${pageContext.request.contextPath}\style\index.css" rel="stylesheet">--%>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}\style\index.css">
    <style>

    </style>
</head>
<nav class="navbar">
    <div class="nav-content">
        <div class="nav-brand">图书交易平台 &nbsp; 欢迎您，${sessionScope.student}</div>
        <div class="nav-menu">
            <a href="${pageContext.request.contextPath}/cart/list" class="nav-link">
                <i class="material-icons">shopping_cart</i>
                购物车
            </a>
            <a href="personal?studentId=${sessionScope.studentId}" class="nav-link">
                <i class="material-icons" >person</i>
                ${requestScope.student.name}
            </a>
            <a href="logout" class="nav-link">
                <i class="material-icons">logout</i>
                退出登录
            </a>
        </div>
    </div>
</nav>

<div class="container">
    <div class="dashboard">
        <div class="stat-card">
            <div class="stat-icon student-icon">
                <i class="material-icons">people</i>
            </div>
            <div class="stat-info">
                <div class="stat-value">${requestScope.students.size()}</div>
                <div class="stat-label">学生总数</div>
            </div>
        </div>
        <div class="stat-card">
            <div class="stat-icon book-icon">
                <i class="material-icons">book</i>
            </div>
            <div class="stat-info">
                <div class="stat-value">${requestScope.books.size()}</div>
                <div class="stat-label">图书总数</div>
            </div>
        </div>
    </div>

    <section class="section">
        <div class="section-header">
            <h2 class="section-title">
                <i class="material-icons">people</i>
                学生信息管理
            </h2>
            <div>
                <a href="studentList" class="btn btn-primary">
                    <i class="material-icons">list</i>查看全部
                </a>
                <a href="addstudent.jsp" class="btn btn-success">
                    <i class="material-icons">add</i>添加学生
                </a>
            </div>
        </div>
        <div class="table-container">
            <table>
                <thead>
                <tr>
                    <th>序号</th>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>年级</th>
                    <th>班级</th>
                    <th>邮箱</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${requestScope.students}" var="student">
                    <tr>
                        <td>${student.id}</td>
                        <td>${student.studentId}</td>
                        <td>${student.name}</td>
                        <td>${student.grade}</td>
                        <td>${student.classes}</td>
                        <td>${student.email}</td>
                        <td class="action-buttons">
                            <a href="getid?id=${student.id}" class="btn action-btn btn-primary">
                                <i class="material-icons">edit</i>
                            </a>
                            <a href="deleteStudent?id=${student.id}"
                               class="btn action-btn btn-danger"
                               onclick="return confirm('确定要删除该学生信息吗？')">
                                <i class="material-icons">delete</i>
                            </a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </section>

    <section class="section">
        <div class="section-header">
            <h2 class="section-title">
                <i class="material-icons">book</i>
                图书信息管理
            </h2>
            <div>
                <a href="bookList" class="btn btn-primary">
                    <i class="material-icons">list</i>查看全部
                </a>
                <a href="addbook.jsp" class="btn btn-success">
                    <i class="material-icons">add</i>添加图书
                </a>
            </div>
        </div>
        <div class="table-container">
            <table>
                <thead>
                <tr>
                    <th>序号</th>
                    <th>书名</th>
                    <th>作者</th>
                    <th>出版社</th>
                    <th>价格</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${requestScope.books}" var="book">
                    <tr>
                        <td>${book.id}</td>
                        <td>${book.name}</td>
                        <td>${book.author}</td>
                        <td>${book.publisher}</td>
                        <td>${book.price}</td>
                        <td class="action-buttons">
                            <a href="bookgetid?id=${book.id}" class="btn action-btn btn-primary">
                                <i class="material-icons">edit</i>
                            </a>
                            <a href="deletebook?id=${book.id}"
                               class="btn action-btn btn-danger"
                               onclick="return confirm('确定要删除该图书信息吗？')">
                                <i class="material-icons">delete</i>
                            </a>
                            <c:choose>
                                <c:when test="${sessionScope.studentId != null}">
                                    <a href="cart/add?bookId=${book.id}&bookName=${book.name}&price=${book.price}"
                                       class="btn action-btn btn-success">
                                        <i class="material-icons">add_shopping_cart</i>
                                    </a>
                                </c:when>
                                <c:otherwise>
                                    <a href="login.jsp"
                                       class="btn action-btn btn-success"
                                       onclick="alert('请先登录')">
                                        <i class="material-icons">add_shopping_cart</i>
                                    </a>
                                </c:otherwise>
                            </c:choose>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </section>
</div>
</body>
</html>
